package main

import (
	"context"
	"github.com/go-redis/redis/v8"
	"strconv"
	"strings"
	"sync/atomic"
	"time"
)

func main() {
	TestRedisSize(10)
	//TestRedisSize(20)
	//TestRedisSize(50)
	//TestRedisSize(100)
	//TestRedisSize(200)
	//TestRedisSize(1000)
	//TestRedisSize(5000)
}

type KeyGenerate struct {
	value int32
}

func NewKeyGenerate() *KeyGenerate {
	return &KeyGenerate{}
}

func (k *KeyGenerate) NextKey() string {
	str := "000000" + strconv.FormatInt(int64(atomic.AddInt32(&k.value, 1)), 10)
	return str[len(str)-6:]
}

func NewRedisClient() *redis.Client {
	return redis.NewClient(&redis.Options{
		Addr:     "127.0.0.1:6379",
		Password: "redis@123",
		DB:       0,
	})
}

var CountOfSize = map[int32]int32{
	10:   500000,
	20:   500000,
	50:   500000,
	100:  200000,
	200:  200000,
	1000: 100000,
	5000: 50000,
}

func ExampleValueOfSize(size int32) string {
	return strings.Repeat("*", int(size))
}

func TestRedisSize(size int32) {
	client := NewRedisClient()
	count := CountOfSize[size]

	keyGenerate := NewKeyGenerate()

	exampleValue := ExampleValueOfSize(size)

	for i := int32(0); i < count; i++ {
		client.SetEX(context.Background(), keyGenerate.NextKey(), exampleValue, 1*time.Minute)
	}
}
